<!--
* description: 物流节点信息
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      v-if="initTemplate"
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsColumnDrop="true"
      :callbackObj="callbackObj"
    >
    <!-- 具名插槽 -->
      <template slot="controlBtn" slot-scope="scope">
        <el-button
          type="primary"
          size="mini"
          class="el-icon-edit"
          @click="edit(scope.row.index)"
          >编辑</el-button
        >
      </template>
    </one-table-template>
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { wmsApis } from "@/api/wms/onStock/api";
import OneTableTemplate from "@/components/wms/templates/oneTable";
import request from "@/utils/request";
export default {
  name: "stockQuery",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate,
  },
  watch: {
    $route(val) {
      if (
        this.formField.pageId !== "" &&
        this.$route.query.pageId !== undefined &&
        this.$route.query.pageId !== this.formField.pageId
      ) {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
        this.queryTable();
      }
    },
  },
  created() {
    if (this.$route.query != null) {
      // 判断传入query参数，初始化数据
      if (this.$route.query.pageId != null && this.$route.query.pageId !== "") {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
      }
    }
    this.querySelect();
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: wmsApis.queryStorageC,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(),
          name: "search",
          position: "right",
          text: "查询", //"查询"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: "重置", //"重置"
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          clickEvent: () => this.export(),
          name: "export",
          position: "left",
          text: "导出", //"导出"
        },
      ],
      // 动态组件-查询条件
      tableComponents: [
      
        {
          compKey: "compKey2",
          labelName: "物流商代码",
          codeField: "TRANSID",
          component: () => import("@/components/wms/commonInput"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: [],
        },
      {
          compKey: "compKey3",
          labelName: "出库单号",
          codeField: "ORDERNO",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
        },
            {
          compKey: "compKey4",
          labelName: "主机厂订单号",
          codeField: "SOURCE_ORDER_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: []
        },
       
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "TRANSID",
          label: "物流商代码",
          align: "center",
        },
        {
          prop: "FACTCARNO",
          label: "运输车牌号",
          align: "center",
        },
        {
          prop: "ORDERNO",
          label: "出库单号",
          align: "center",
        },
          {
          prop: "SOURCE_ORDER_CODE",
          label: "主机厂订单号",
          align: "center"
        },
        {
          prop: "LASTTIME",
          label: "当前时点",
          align: "center",
        },
        {
          prop: "CURRENTPLACE",
          label: "当前地点",
          align: "center",
        },
        {
          prop: "DRIVER",
          label: "司机名称",
          align: "center",
        },
        {
          prop: "PHONE",
          label: "司机联系方式",
          align: "center",
        },
        {
          prop: "LASTPLACE",
          label: "上一地点",
          align: "center",
        },

        {
          prop: "CREATED_DATE",
          label: "接收时间",
          align: "center",
        },
      ],
      //表单查询数据
      formField: {
        TRANSID: "",
        FACTCARNO: "",
        ORDERNO: "",
        LASTTIME: "",
        CURRENTPLACE: "",
        DRIVER: "",
        PHONE: "",
        LASTPLACE: "",
        CREATED_DATE: "",
        SOURCE_ORDER_CODE:""
      },
      unFormField: {},
      // 控制初始化页面
      initTemplate: false,
      callbackObj: {
        onAfterReset: () => {
          this.queryArea();
        },
      },
    };
  },
  methods: {
    // 0、
    querySelect() {
      // request({
      //   url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",      
      //   method: "post",
      //   data: {
      //     IS_ENABLE: "1",
      //   },
      // }).then((res) => {
      //   if (res.listRow && res.listRow.length > 0) {
      //     res.listRow.map((item) => {
      //       this.tableComponents[0].options.push({
      //         label: item.WAREHOUSE_NAME,
      //         value: item.WAREHOUSE_ID,
      //       });
      //     });
      //     this.formField.WAREHOUSE_IDS = res.listRow[0].WAREHOUSE_ID;
      //     this.queryArea();
      //   }
        this.initTemplate = true;
        this.$nextTick(() => {
          this.queryTable();
        });
      // });
    },
    export() {
      const exportLoading = this.$loading({
        lock: true,
        text: "正在导出...",
        // spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        fullscreen: true,
      });
      request({
        url: "/mp/wm/vl/warehouse/LogisticsInformationService/exportNodeInformation.do",
        method: "post",
        headers: {
          "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
          Pragma: "no-cache",
          Expires: "0",
          "Content-Type": "application/json;charset=UTF-8",
        },
        responseType: "blob",
        data: this.formField,
      })
        .then((response) => {
          exportLoading.close();
          let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
          let downloadElement = document.createElement("a");
          let href = window.URL.createObjectURL(blob); // 创建下载的链接
          downloadElement.href = href;
          downloadElement.download = "物流节点导出.xls"; // 下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); // 点击下载
          document.body.removeChild(downloadElement); // 下载完成移除元素
          window.URL.revokeObjectURL(href); // 释放掉blob对象
        })
        .catch((err) => {
          exportLoading.close();
          console.log(err);
        });
    },
  },
};
</script>
